package com.company.oa.meeting.controller;

import com.company.oa.common.api.Result;
import com.company.oa.common.utils.SecurityUtils;
import com.company.oa.meeting.entity.MeetingAttachment;
import com.company.oa.meeting.service.MeetingAttachmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * 会议附件控制器
 */
@RestController
@RequestMapping("/meeting-attachments")
public class MeetingAttachmentController {

    @Autowired
    private MeetingAttachmentService meetingAttachmentService;

    /**
     * 获取会议附件列表
     */
    @GetMapping("/meeting/{meetingId}")
    public Result<List<MeetingAttachment>> getByMeetingId(@PathVariable Long meetingId) {
        List<MeetingAttachment> attachments = meetingAttachmentService.getByMeetingId(meetingId);
        return Result.success(attachments);
    }

    /**
     * 上传会议附件
     */
    @PostMapping("/upload")
    public Result<Long> uploadAttachment(
            @RequestParam("file") MultipartFile file,
            @RequestParam("meetingId") Long meetingId) {
        Long userId = SecurityUtils.getUserId();
        String userName = SecurityUtils.getUsername();
        
        Long attachmentId = meetingAttachmentService.uploadAttachment(file, meetingId, userId, userName);
        return Result.success(attachmentId);
    }

    /**
     * 删除会议附件
     */
    @DeleteMapping("/{id}")
    public Result<Boolean> deleteAttachment(@PathVariable Long id) {
        boolean result = meetingAttachmentService.deleteAttachment(id);
        return Result.success(result);
    }
}